package com.wk1un2.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wk1un2.service.StudentsService;
import com.wk1un2.util.Result;

@RestController
public class StudentsController {
	@Autowired
	private StudentsService studentsservice;

	@RequestMapping("/getAllStudents")
	public Object getAll(@RequestParam Map<String, Object> map) {
		Integer page = Integer.parseInt(map.get("page").toString());
		Integer limit = Integer.parseInt(map.get("limit").toString());
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		
		System.out.println(map);
		Result res = new Result(0, "true", studentsservice.count(map), studentsservice.getAll(map));
		return res;
	}

	@RequestMapping("/addStudents")
	public Object add(@RequestParam Map<String, Object> map) {
		map.put("s_card", new Date().getTime());
		Result res = new Result(0, "true", studentsservice.add(map), true);
		return res;
	}

	@RequestMapping("/updateStudents")
	public Object update(@RequestParam Map<String, Object> map) {
		map.put("s_card", new Date().getTime());
		Result res = new Result(0, "true", studentsservice.update(map), true);
		return res;
	}

	@RequestMapping("/deleteStudents")
	public Object delete(Integer s_id) {
		Result res = new Result(0, "true", studentsservice.delete(s_id), true);
		return res;
	}
}
